﻿namespace clock;

using System.Timers;

public class Clock
{
    private int record;
    private int always;
    private int once;

    public event EventHandler<EventArgs> addOnce;
    public event EventHandler<EventArgs> addAlways;


    private System.Timers.Timer timer;

    public Clock(int always, int once) // s为单位
    {
        record = 0;
        this.always = always*1000;
        this.once = once*1000;
        timer = new System.Timers.Timer(10);
        timer.Enabled = true;
        timer.Elapsed += new ElapsedEventHandler(reacordAdd);
        timer.AutoReset = true;
    }

    private void reacordAdd(object source, ElapsedEventArgs e)
    {
        record+=10;
        if (record%always == 0)
        {
            addAlways(this,EventArgs.Empty);
        }

        if (record == once)
        {
            addOnce(this,EventArgs.Empty);
        }
    }

    public void begin()
    {
        timer.Start();
    }

}